package com.huike.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.huike.clues.domain.Business;
import com.huike.clues.dto.BusinessDTO;
import com.huike.clues.service.BusinessService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business")
@Api(tags = "商机管理")

public class BusinessController extends BaseController {

    @Autowired
    private BusinessService businessService;

    @GetMapping("/list")
    public TableDataInfo list(BusinessDTO dto) {
        startPage();
        List<Business> businessList = businessService.selectBusinessList(dto);
        return getDataTable(businessList);
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable("id") Long id) {
        Business business = businessService.selectById(id);
        return AjaxResult.success(business);
    }
    @GetMapping("/pool")
    public TableDataInfo poolList(BusinessDTO dto) {
        startPage();
        List<Business> businessList = businessService.selectBusinessPoolList(dto);
        return getDataTable(businessList);
    }
    @ApiOperation("捞取商机")
    @PutMapping("/gain")
    public AjaxResult BusinessGain(@RequestBody Map<String,List<Integer>> map){
        List<Integer> ids = map.get("ids");
        int row = businessService.BusinessGain(ids);
        return toAjax(row);
    }

    @ApiOperation("新建商机")
    public AjaxResult addBusiness(@RequestBody Business business){
        return toAjax(businessService.addBusiness(business));
    }

}
